import { ELogChangeID } from "../constant/GameEnum";
import LogPokerVo from "./LogPokerVo";
import ModelAI, { AiPoker } from "./ModelAI";
import ModelGame from "./ModelGame";

export default class GameCtrl {
  public isGameOver: boolean = false;
  public isAutoReceiveIng: boolean = false;
  public isAIAutoPlayIng: boolean = false;

  private constructor() {
    this.isAIAutoPlayIng = false;
    this.isAutoReceiveIng = false;
    this.isGameOver = false;
  }

  public newGame(): void {
    if (this.clearancePokers.length < 5) {
      this.creatrAI();
    }
    this._logPokers = [];
    this.isAIAutoPlayIng = false;
    this.isAutoReceiveIng = false;
    this.isGameOver = false;
    ModelGame.ins.init();
    ModelGame.ins.onPlay();
  }

  /**
   * AI模拟玩牌
   */
  public creatrAI(): void {
    for (let index = 0; index < 100; index++) {
      let modelAI: ModelAI = new ModelAI();
      modelAI.AIplay();
    }
  }

  /********  getter & setter  ********/

  /**记录操作步骤 */
  private _logPokers: LogPokerVo[];
  public get haveLogPoker(): boolean {
    return this._logPokers.length > 0;
  }
  public get logPoker(): boolean {
    return this._logPokers != null;
  }
  //添加操作
  public addLogPoker(log: LogPokerVo): void {
    this._logPokers.push(log);
  }
  //获取最后一条数据并删除
  public popLogPoker(): LogPokerVo {
    return this._logPokers.pop();
  }
  // 获取最后一条数据是否是移动
  public get nextLogPokerIsMove(): boolean {
    if (this._logPokers.length == 0) {
      return true;
    }
    return this._logPokers[this._logPokers.length - 1].isMove == ELogChangeID.Move;
  }
  /**
   * 储存可通关的牌局
   */
  private _clearancePokers: AiPoker[] = [];
  public addCanGameOverPoker(aiPoker: AiPoker) {
    this._clearancePokers.push(aiPoker);
  }
  public getCanGameOverPoker(id: number): AiPoker {
    return this._clearancePokers[id];
  }
  public get clearancePokers(): AiPoker[] {
    return this._clearancePokers;
  }
  public popClearancePokers(): AiPoker {
    return this._clearancePokers.pop();
  }
  private static _ins: GameCtrl;
  public static get ins(): GameCtrl {
    return (GameCtrl._ins = GameCtrl._ins || new GameCtrl());
  }
}
